#!/usr/bin/env python3
#===============================================================================

HEAD = """
#!/bin/bash

dir="${1}"
shift 1

if [ -z "${dir}" ]
then
    1>&2 echo "usage:"
    1>&2 echo "  ${0} <directory> [<option>]"
    exit 1
fi

set -x
""".lstrip()

BODY = """
"""

#===============================================================================

import scrap
import os

def sh_is_exec(fname):
    # if we don't have an extension or our extension is .sh then we're
    # executable.
    return scrap.isext(fname, None) or scrap.isext(fname, '.sh')

def sh_gen(is_exec):
    out = ''
    if is_exec:
        out += HEAD
    out += BODY
    return out

fpath = scrap.mkscript(is_exec=sh_is_exec, gen=sh_gen)
if fpath:
    scrap.edit(fpath)

